<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统主页</title>
    <style>
        /* 保持原有样式不变 */
        body {
            font-family: "Microsoft YaHei", sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f8f9fa;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            width: 800px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        .header {
            background: linear-gradient(90deg, #2c53b4, #1a3a8a);
            color: #fff;
            padding: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .header .user-info {
            display: flex;
            align-items: center;
        }
        .header .avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: #fff;
            color: #2c53b4;
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: bold;
            margin-right: 10px;
            font-size: 18px;
        }
        .header .welcome {
            font-size: 16px;
        }
        .header .logout-btn {
            background-color: #ff4d4f;
            color: #fff;
            border: none;
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .header .logout-btn:hover {
            background-color: #f5222d;
        }
        .main {
            padding: 20px;
        }
        .section {
            background-color: #f9fafb;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
        }
        .section h3 {
            margin-top: 0;
            color: #333;
            border-bottom: 1px solid #eee;
            padding-bottom: 10px;
        }
        .feature-list {
            list-style: none;
            padding: 0;
        }
        .feature-list li {
            padding: 12px 0;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
        }
        .feature-list li a {
            text-decoration: none;
            color: #2c53b4;
        }
        .activity-item {
            margin: 4px 0;
            color: #666;
        }
        #current-time {
            color: #2c53b4;
            font-weight: 500;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="user-info">
                <div class="avatar" id="avatar"></div>
                <div class="welcome" id="welcomeText"></div>
            </div>
            <button class="logout-btn" id="logoutButton">退出登录</button>
        </div>
        <div class="main">
            <div class="section">
                <h3>功能导航</h3>
                <ul class="feature-list">
                    <!-- <li>录入数据 <a href="insert.html">进入</a></li> -->
                    <li>进入测试 <a href="verify.html">进入</a></li>
                    <li>帮助中心 <a href="#">进入</a></li>
                </ul>
            </div>
            <div class="section">
                <h3>最近活动</h3>
                <div class="activity-item">• 上次登录地点：本地设备</div>
                <div class="activity-item">• 系统当前时间：<span id="current-time">加载中...</span></div>
            </div>
        </div>
    </div>
    <script>
        // 1. 动态加载用户信息
        function loadUserInfo() {
            const username = sessionStorage.getItem('username');
            // 未登录则跳转回登录页
            if (!username) {
                window.location.href = 'login.html';
                return;
            }
            // 渲染欢迎语
            document.getElementById('welcomeText').textContent = `欢迎回来，${username}`;
            // 渲染头像（首字母）
            const firstChar = username.charAt(0).toUpperCase();
            document.getElementById('avatar').textContent = firstChar;
        }

        // 2. 时间更新函数（保持不变）
        function updateCurrentTime() {
            const now = new Date();
            const year = now.getFullYear();
            const month = String(now.getMonth() + 1).padStart(2, '0');
            const day = String(now.getDate()).padStart(2, '0');
            const hours = String(now.getHours()).padStart(2, '0');
            const minutes = String(now.getMinutes()).padStart(2, '0');
            const seconds = String(now.getSeconds()).padStart(2, '0');
            const formattedTime = `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
            document.getElementById('current-time').textContent = formattedTime;
        }

        // 3. 页面加载时执行
        window.onload = function() {
            loadUserInfo(); // 优先加载用户信息
            updateCurrentTime();
            setInterval(updateCurrentTime, 1000);
        };

        // 4. 退出登录逻辑
        document.getElementById('logoutButton').addEventListener('click', function() {
            sessionStorage.removeItem('username'); // 清除登录状态
            window.location.href = 'login.html';
        });
    </script>
</body>
</html>